from src.GameConfig import *

BULLET_TYPE_HERO_SMALL = "h_small"
BULLET_TYPE_HERO_MIDLE = "h_midle"
BULLET_TYPE_HERO_BIG = "h_big"


# 子弹基类
class BaseBullet(pygame.sprite.Sprite):

    def __init__(self, imagePath, x, y):
        pygame.sprite.Sprite.__init__(self)
        self.image = pygame.image.load(imagePath).convert_alpha()
        self.rect = self.image.get_rect()
        self.rect.centerx = x
        self.rect.bottom = y
        self.speed = 12
        self.harm = 1  # 伤害值
        self.is_alive = True
        self.mask = pygame.mask.from_surface(self.image)  # 用于完美碰撞检测

    # 步骤帧
    def step(self, step):
        self.__move()

    def onDraw(self, canvas):
        canvas.blit(self.image, self.rect)

    # 子弹移动
    def __move(self):
        self.rect.top -= self.speed
        # 超过边界则消失
        if self.rect.bottom < 0 or self.rect.y > SCREEN_RECT.height:
            self.is_alive = False
            self.died()

    # 死亡状态回收资源
    def died(self):
        self.kill()


# 子弹
class Bullet(BaseBullet):

    def __init__(self, type, x, y):
        imagePath = object
        speed = object
        harm = object
        if type == BULLET_TYPE_HERO_SMALL:
            imagePath = BASE_RESOURCE_PATH_IMAGE+"bullet1.png"
            speed = 5
            harm = 1
        elif type == BULLET_TYPE_HERO_MIDLE:
            imagePath = BASE_RESOURCE_PATH_IMAGE+"bullet2.png"
            speed = 5
            harm = 1
        elif type == BULLET_TYPE_HERO_BIG:
            imagePath = BASE_RESOURCE_PATH_IMAGE+"bullet2.png"
            speed = 3
            harm = 2
        super(Bullet, self).__init__(imagePath, x, y)
        self.speed = speed
        self.harm = harm
